package com.ruoyi.report.controller;

import com.ruoyi.api.system.utils.ShiroUtils;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.report.domain.ReportAttend;
import com.ruoyi.report.service.IReportAttendService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 * 考勤汇总 Controller
 *
 * @author ruoyi
 * @date 2022-09-26
 */
@Controller
@RequestMapping("/report/attend")
public class ReportAttendController extends BaseController {

    private String prefix = "report/attend";

    @Autowired
    private IReportAttendService reportAttendService;

    @GetMapping()
    public String attend(ModelMap mmap)
    {
        mmap.put("attendMonth", DateUtils.getMonth());
        return prefix + "/attend";
    }

    /**
     * 查询考勤统计
     */
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(ReportAttend reportAttend)
    {
        startPage();
        List<ReportAttend> list = reportAttendService.selectReportAttendList(reportAttend);
        return getDataTable(list);
    }

    @GetMapping("/unattend")
    public String unattend(ModelMap mmap)
    {
        mmap.put("attendMonth", DateUtils.getMonth());
        return prefix + "/unattend";
    }

    /**
     * 查询考勤统计
     */
    @PostMapping("/unlist")
    @ResponseBody
    public TableDataInfo unlist(ReportAttend reportAttend)
    {
        startPage();
        if(!ShiroUtils.getSysUser().isAdmin()) {
            reportAttend.setDeptId(ShiroUtils.getDeptId());
        }
        List<ReportAttend> list = reportAttendService.selectUnReportAttendList(reportAttend);
        return getDataTable(list);
    }
}
